// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.input;

import org.lwjglx.input.Controller;
import org.lwjglx.input.Controllers;
import org.lwjglx.input.GamepadState;

public class ControllerState {
    private boolean m_isCreated = false;
    private boolean m_wasPolled = false;
    private final Controller[] m_controllers = new Controller[16];
    private final GamepadState[] m_gamepadState = new GamepadState[16];

    ControllerState() {
        for (int _int = 0; _int < this.m_controllers.length; _int++) {
            this.m_gamepadState[_int] = new GamepadState();
        }
    }

    public void poll() {
        boolean _boolean = !this.m_isCreated;
        this.m_isCreated = this.m_isCreated || Controllers.isCreated();
        if (this.m_isCreated) {
            if (_boolean) {
            }

            this.m_wasPolled = true;
            Controllers.poll(this.m_gamepadState);

            for (int _int = 0; _int < Controllers.getControllerCount(); _int++) {
                this.m_controllers[_int] = Controllers.getController(_int);
            }
        }
    }

    public boolean wasPolled() {
        return this.m_wasPolled;
    }

    public void set(ControllerState rhs) {
        this.m_isCreated = rhs.m_isCreated;

        for (int _int = 0; _int < this.m_controllers.length; _int++) {
            this.m_controllers[_int] = rhs.m_controllers[_int];
            if (this.m_controllers[_int] != null) {
                this.m_gamepadState[_int].set(rhs.m_gamepadState[_int]);
                this.m_controllers[_int].gamepadState = this.m_gamepadState[_int];
            }
        }

        this.m_wasPolled = rhs.m_wasPolled;
    }

    public void reset() {
        this.m_wasPolled = false;
    }

    public boolean isCreated() {
        return this.m_isCreated;
    }

    public Controller getController(int _int) {
        return this.m_controllers[_int];
    }

    public void quit() {
        for (int _int = 0; _int < this.m_controllers.length; _int++) {
            this.m_gamepadState[_int].quit();
        }
    }
}
